package middleware

import (
	"gf-app/app/lib/error_msg"
	"gf-app/app/lib/resp"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/os/glog"
	"net/http"
)

func ErrorHandlerMiddleware(r *ghttp.Request) {
	r.Middleware.Next()
	if r.Response.Status >= http.StatusInternalServerError{
		glog.Error(r.Response.BufferString())
		r.Response.ClearBuffer()
		//处理500错误响应，统一返回`程序运行期错误`
		r.Response.WriteStatus(200,"")
		resp.Error(r,error_msg.RUNTIME_ERROR)
	}
}
